﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickApp.MVCControl;
using QuickApp.Core;
using EfSearchModel.Model;

namespace Resto.CostControl.Core
{
    /// <summary>
    /// 分页信息的扩展方法
    /// </summary>
    public static class PageInfoExtensions
    {
        /// <summary>
        /// 获取枚举项的扩展信息
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static PageInfo ToPageInfo(this DWZPageInfo p)
        {
            return new PageInfo
            {
                PageIndex = p.PageIndex,
                PageSize = p.PageSize,
                SortName = p.SortName,
                SortOrder = p.SortOrder,
            };
        }

        /// <summary>
        /// 增加一个查询条件，默认方式是等于
        /// </summary>
        /// <param name="query"></param>
        /// <param name="key">查询字段</param>
        /// <param name="val">查询值</param>
        /// <param name="method">检索方式，默认是等于</param>
        /// <returns></returns>
        public static DWZQueryModel AddItem(this DWZQueryModel query, string key, string val, QueryMethod method = QueryMethod.Equal)
        {
            if (string.IsNullOrWhiteSpace(key))
                throw new ArgumentNullException(key, "key");

            query.Items.Add(new ConditionItem
                {
                    Field = key,
                    Value = val,
                    Method = method,
                });

            return query;
        }
    }
}
